package com.lwj.liwanjia.presenter;

import com.lwj.liwanjia.bean.SeckillBean;
import com.lwj.liwanjia.impl.SeckillView;
import com.lwj.liwanjia.model.SeckillModel;

import rx.Subscriber;

/**
 * Created by Administrator on 2017/9/10.
 */

public class SeckillPresenter {
    private SeckillModel seckillModel;
    private SeckillView seckillView;

    public SeckillPresenter(SeckillView seckillView) {
        this.seckillView = seckillView;
        seckillModel = new SeckillModel();
    }

    public void getSeckillData() {
        if (seckillView != null) {
            seckillModel.getSeckillData( new Subscriber<SeckillBean>() {
                @Override
                public void onCompleted() {
                    seckillView.hideProgress();
                }

                @Override
                public void onError(Throwable e) {
                    seckillView.showError((Exception) e);
                    seckillView.hideProgress();
                }

                @Override
                public void onNext(SeckillBean seckillBean) {
                    seckillView.getSeckillData(seckillBean);
                }

                @Override
                public void onStart() {
                    super.onStart();
                    seckillView.showProgress();
                }
            });
        }
    }
}
